package com.example.mobwe_project;

import java.util.ArrayList;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.GridView;
import android.widget.TextView;

public class MenuActivity extends Activity implements OnItemClickListener {

	private EditText textAutor;
	private GridView gridView;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_menu);
		this.gridView = (GridView) findViewById(R.id.gridView1);
		
		ImageAdapter adapter=new ImageAdapter(this);
		adapter.loadThumbnails();
	
	
		 
        // Instance of ImageAdapter Class
        gridView.setAdapter(adapter);
       
        
        
        gridView.setOnItemClickListener(this);
	  
        Button bk=(Button)findViewById(R.id.button1);
        bk.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				getBack();
				
			}
        });
			
    }
	
	protected void getBack() {
		Intent back=new Intent(this,MainActivity.class);
		startActivity(back);
		
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.activity_menu, menu);
		return true;
	}

	@Override
	public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
		// int position, long id;
   		 // Sending image id to FullScreenActivity
            Intent i = new Intent(getApplicationContext(), BookDetails.class);
            
            // passing array index
            i.putExtra("id", position);
            ImageAdapter adapter = (ImageAdapter)gridView.getAdapter();
            ArrayList<Ebook> ebooks = adapter.getEbooks();
            Ebook ebook = ebooks.get( position );

            i.putExtra("bookId", ebook.getId());
            //i.putExtra("bookId", ebook.getAuthor());
           
           
            
           
            
            //ebook.setId("test");
     
            //i.putExtra("ebook", ebook);
           
         // findViewById(R.id.editText1)
//           textAutor=(EditText) findViewById(R.id.editText1);
//           textAutor.setText("dasfcsa");
            
            startActivity(i);		
	}

}
